How to find all combinations of values in rows of an M x N array